var city = "泊头"

function loadXMLDoc() {
	var xmlhttp;
	if (window.XMLHttpRequest) {
		//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
		xmlhttp = new XMLHttpRequest();
	}
	else {
		// IE6, IE5 浏览器执行代码
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange = function () {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			var json = JSON.parse(xmlhttp.responseText)
			document.querySelector("#city").innerHTML = json.basic.city
			document.querySelector("#whte").innerHTML = json.now.cond.txt
			
			
			
			
			for (let t = 0; t < json.daily_forecast.length; t++) {
//				console.log(json.daily_forecast[t].wind.sc)
				var dert = document.querySelector(".mei .dert")
				var li = document.createElement("li")
				dert.appendChild(li)
				var day = json.daily_forecast[t].date.substring(8, 10) + "日"
				var wer = json.daily_forecast[t].cond.txt_n
				var qwe = json.daily_forecast[t].tmp.max + "/" + json.daily_forecast[t].tmp.min + "℃"
				var qre = json.daily_forecast[t].wind.dir
				var ji = json.daily_forecast[t].wind.sc + "级"
				var p = document.createElement("p")
				var p2 = document.createElement("p")
				var p3 = document.createElement("p")
				var p4 = document.createElement("p")
				var p5 = document.createElement("p")
				p2.classList.add("p2")
				p3.classList.add("p3")
				p4.classList.add("p4")
				p5.classList.add("p5")
				p.classList.add("p")
				li.appendChild(p)
				li.appendChild(p2)
				li.appendChild(p3)
				li.appendChild(p4)
				li.appendChild(p5)
				p.innerHTML = day
				p2.innerHTML = wer
				p2.innerHTML = wer
				p3.innerHTML = qwe
				p4.innerHTML = qre
				p5.innerHTML = ji
			}
			
			
			
			for (let i = 0; i < json.hourly_forecast.length; i++) {
				//                        console.log(json)
				var da = json.hourly_forecast[i].date.substring(8, 10) + "日 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
				var h = json.hourly_forecast[i].date.substring(11, 13) + "时 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
				var de = json.hourly_forecast[i].cond.txt
				if (de.length == 1) {
					de = de + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "
				}
				if (de.length == 2) {
					de = de + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "
				}
				var she = json.hourly_forecast[i].tmp + "℃ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
				var feng = json.hourly_forecast[i].wind.dir
					//                        console.log(she)
					//                        console.log(h)
				var sda = document.querySelector(".sda")
				var li = document.createElement("li")
				li.innerHTML = da + h + she + de + feng
				sda.appendChild(li)
			}
			for(let o=0;o<6;o++){
//				console.log(json.suggestion.air)
				var huo=document.querySelector(".huo ul")
				var li=document.createElement("li")
				var i=document.createElement("i")
				var em=document.createElement("em")
				var p=document.createElement("p")
				var span=document.createElement("span")
				li.appendChild(i)
				li.appendChild(span)
				li.appendChild(em)
				li.appendChild(p)
				huo.appendChild(li)
				 
				if(o==0){
					span.innerHTML=json.suggestion.uv.brf
					em.innerHTML="紫外线指数"
					var jian=json.suggestion.uv.txt
					var cc=jian.indexOf("建议")
					jian=jian.substring(cc)
					p.innerHTML=jian
				}
				if(o==1){
					span.innerHTML=json.suggestion.sport.brf
					em.innerHTML="减肥指数"
					var jian=json.suggestion.sport.txt
//					console.log(jian)
					var cc=jian.indexOf("推荐")
//					console.log(cc)
					jian=jian.substring(cc)
					p.innerHTML=jian
				}
				if(o==2){
					span.innerHTML=json.suggestion.flu.brf
					em.innerHTML="疾病指数"
					var jian=json.suggestion.flu.txt 
					p.innerHTML=jian
				}
				if(o==3){
					span.innerHTML=json.suggestion.drsg.brf
					em.innerHTML="穿衣指数"
					var jian=json.suggestion.drsg.txt 
					p.innerHTML=jian
				}
				if(o==4){
					span.innerHTML=json.suggestion.cw.brf
					em.innerHTML="洗车指数"
					var jian=json.suggestion.cw.txt 
					p.innerHTML=jian
				}
				if(o==5){
					span.innerHTML=json.suggestion.air.brf
					em.innerHTML="空气指数"
					var jian=json.suggestion.air.txt 
					p.innerHTML=jian
				}
			}
		}
	}
	xmlhttp.open("GET", "https://bird.ioliu.cn/weather?city=" + city, true);
	xmlhttp.send();
}
loadXMLDoc()
document.querySelector("#ipt").addEventListener('change', function () {
//	console.log(this.value)
	city = this.value
	var sda = document.querySelector(".sda")
	sda.innerHTML = ""
	var dert = document.querySelector(".mei .dert")
	dert.innerHTML = ""
	var huo=document.querySelector(".huo ul")
	huo.innerHTML=""
	loadXMLDoc()
	this.value = ""
})
var dr = document.querySelectorAll(".zong>div")
	//        console.log(dr)
var em = document.querySelectorAll(".but em")
for (let i = 0; i < em.length; i++) {
	em[i].addEventListener('click', function () {
		for (let y = 0; y < em.length; y++) {
			em[y].classList.remove("on")
			dr[y].classList.add("non")
		}
		this.classList.add("on")
		dr[i].classList.remove("non")
//		console.log(i)
	})
}